package io.gitee.thinkbungee.mybatis.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Map;

/**
 * 查询工具类,将参数map组装成查询page
 *
 * @author chenyichang
 * @email 820117089@qq.com
 * @date 2022-05-25 18:25:32
 */
public class QueryUtils<T> {

    public static <T> IPage<T> getPage(Map<String, Object> params) {
        long curPage = 1;
        long limit = 10;
        if (params.get("page") != null) {
            curPage = Long.parseLong((String) params.get("page"));
        }
        if (params.get("limit") != null) {
            limit = Long.parseLong((String) params.get("limit"));
        }

        Page<T> page = new Page<>(curPage, limit);
        return page;
    }
}
